import moment from 'moment'

export const handleChangeGroup = (data) => {
  const { diagItems, basicInfo, diagInfo, chargeInfo, amountTotal } = data

  // 获取诊断列表
  const diagnosesList = diagItems.reduce((acc, item) => {
    if (item.way === 1) {
      acc.push({
        medicalInsuranceCode: item.code || '',
        medicalInsuranceName: item.name || '',
        isMain: item.type == 1 ? 1 : 0,
      })
    }
    return acc
  }, [])

  // 获取手术列表
  const operationsList = diagInfo.operItems.map((item) => ({
    medicalInsuranceCode: item.operCode || '',
    medicalInsuranceName: item.operName || '',
    isMain: item.type,
  }))

  return {
    insuedType: basicInfo.insureType,
    totalCost: amountTotal,
    diagnoses: diagnosesList,
    operation: operationsList,
    mainDiagnoseCode: diagItems.length > 0 ? diagItems[0].code : '',
    leaveType: diagInfo.outWay,
    days: diagInfo.inDays,
    age: basicInfo.age,
    age_New: basicInfo.age_New,
    bornWeight: basicInfo.newBornOutWeight,
    sexCode: basicInfo.sex,
  }
}

export const shouldTriggerGroup = (type = '', value = '') => {
  switch (type) {
    case 'insureType':
      return [1, 2].includes(Number(value))
    case 'outWay':
      return ['5', '9'].includes(value)
    case 'sex':
      return ['1', '2'].includes(value)
    default:
      return true
  }
}
